/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/19 23:53
  *
  * @file       pd_dma.h
  * @brief      Header file of DMA peripheral driver.
  *
  * @note       This file contains the DMA object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/19     Chris        the first version
  *
  ******************************************************************************
  */

#ifndef JLC_SKY_DMA_H
#define JLC_SKY_DMA_H

#include "stm32f407xx.h"

struct DMAVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    DMA_TypeDef *DMAx;

    uint32_t PeriphOrM2MSrcAddress;
    uint32_t MemoryOrM2MDstAddress;

    uint32_t Direction;
    uint32_t Mode;
    uint32_t PeriphOrM2MSrcIncMode;
    uint32_t MemoryOrM2MDstIncMode;
    uint32_t PeriphOrM2MSrcDataSize;
    uint32_t MemoryOrM2MDstDataSize;

    uint32_t NbData;

    uint32_t Channel;
    uint32_t Priority;
    uint32_t FIFOMode;
    uint32_t FIFOThreshold;
    uint32_t MemBurst;
    uint32_t PeriphBurst;

    uint32_t Stream;


    // DMA virtual table
    struct DMAVtbl *vptr;
} DMA;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct DMAVtbl {
    void (*init)(const DMA *this);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void DMA_constructor(DMA *this, DMA_TypeDef *DMAx,
                     uint32_t PeriphOrM2MSrcAddress,
                     uint32_t MemoryOrM2MDstAddress,
                     uint32_t NbData,
                     uint32_t Channel,
                     uint32_t Stream);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void DMA_init(const DMA *this) {
    this->vptr->init(this);
}
/**
 * @}
 */


#endif //JLC_SKY_DMA_H
